package com.time.workshop.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.time.workshop.R;
import com.time.workshop.SuperActivity;
import com.time.workshop.bean.TimeHallList;
import com.time.workshop.utils.CommonUtils;

public class TimeHallAdapter extends BaseAdapter
{
	private Context context;
	private List<TimeHallList> list;
	private LayoutInflater inflater;
	private ViewHolder holder = null;
	public SuperActivity mSuperActivity;

	public TimeHallAdapter(Context context, List<TimeHallList> list)
	{
		this.context = context;
		this.list = list;
		this.mSuperActivity = (SuperActivity) context;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount()
	{
		return list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return list.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		if (convertView == null)
		{
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_time_hall_list, null);
			holder.head_name = (TextView) convertView.findViewById(R.id.head_name);
			holder.head_ImageView = (ImageView) convertView.findViewById(R.id.head_ImageView);
			holder.bg_ImageView = (ImageView) convertView.findViewById(R.id.bg_ImageView);
			holder.context = (TextView) convertView.findViewById(R.id.context);
			holder.head_statu = (TextView) convertView.findViewById(R.id.head_statu);
			holder.context_time = (TextView) convertView.findViewById(R.id.context_time);
			holder.head_days = (TextView) convertView.findViewById(R.id.head_days);
			holder.time_hall_price = (TextView) convertView.findViewById(R.id.time_hall_price);
			holder.context_address = (TextView) convertView.findViewById(R.id.context_address);
			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}

		holder.head_name.setText(list.get(position).getUSERNAME());
		holder.context.setText(list.get(position).getTITLE());
		holder.head_statu.setText(list.get(position).getSTATUS_NAME());
		holder.context_time.setText(list.get(position).getNEED_TIME());
		holder.head_days.setText(list.get(position).getU_TIME());
		holder.context_address.setText(list.get(position).getNEED_ADDRESS());
		holder.time_hall_price.setText(list.get(position).getPRICE() + "元");
		if (!CommonUtils.isNull_nie(list.get(position).getPIC_URL()))
		{
			ImageLoader.getInstance().displayImage(list.get(position).getPIC_URL(), holder.bg_ImageView, mSuperActivity.getDisplayOption());
		}
		if (!CommonUtils.isNull_nie(list.get(position).getHEADER_IMAGE()))
		{
			ImageLoader.getInstance().displayImage(list.get(position).getHEADER_IMAGE(), holder.head_ImageView, mSuperActivity.getDisplayOption());
		}
		return convertView;
	}

	public final class ViewHolder
	{
		private TextView head_name, context_time, context_address, context, head_statu, head_days, time_hall_price;

		private ImageView head_ImageView, bg_ImageView;
	}

	@Override
	public void notifyDataSetChanged()
	{
		super.notifyDataSetChanged();
	}
}
